var express      = require('express');
var app          = express();
app.use(express.static('public'));
var http = require('http'), 
httpProxy = require('http-proxy');  
    
  // 新建一个代理 Proxy Server 对象  
  var proxy = httpProxy.createProxyServer({});  
    
  // 捕获异常  
  proxy.on('error', function (err, req, res) {  
        res.writeHead(500, {  
            'Content-Type': 'text/plain'  
        });  
       res.end('Something went wrong. And we are reporting acustom error message.');  
 });  

app.all('/*.do', function(req, res) {   
  //对于.do的请求，直接去请求后台数据，此处可以通过一些框架实现mock和生产代理的配置，实现代理，
   proxy.web(req, res, { target: 'http://localhost:1111' });  
})

app.all('/*.html', function(req, res) {  
 console.log("请求"+req.path); 
res.sendFile( __dirname + req.path);
})
     
var server = app.listen(8081, function () {
 
  var host = server.address().address
  var port = server.address().port
 
  console.log("应用实例，访问地址为 http://%s:%s", host, port)
 
})

